# @Author   : XiongBinFei
# @Version  : 1.0
# @Time     : 2025/3/26 14:28

import turtle

def draw_gap():
    turtle.penup()
    turtle.fd(5)

def draw_line(draw):
    draw_gap()
    turtle.pendown() if draw else turtle.penup()
    turtle.fd(40)
    draw_gap()
    turtle.right(90)

def draw_digit(digit):
    # 七段数码管绘制逻辑（共阴极接法）
    draw_line(True) if digit in [2, 3, 4, 5, 6, 8, 9] else draw_line(False)  # a段[1,2](@ref)
    draw_line(True) if digit in [0, 1, 3, 4, 5, 6, 7, 8, 9] else draw_line(False)  # b段
    draw_line(True) if digit in [0, 2, 3, 5, 6, 8, 9] else draw_line(False)  # c段
    draw_line(True) if digit in [0, 2, 6, 8] else draw_line(False)  # d段

    turtle.left(90)  # 调整方向绘制下半部分
    draw_line(True) if digit in [0, 4, 5, 6, 8, 9] else draw_line(False)  # e段[3](@ref)
    draw_line(True) if digit in [0, 2, 3, 5, 6, 7, 8, 9] else draw_line(False)  # f段
    draw_line(True) if digit in [0, 1, 2, 3, 4, 7, 8, 9] else draw_line(False)  # g段

    turtle.left(180)
    turtle.penup()
    turtle.fd(20)


# def draw_date(date_str):
#     colors = ["red", "blue", "green"]
#     color_index = 0
#     for char in date_str:
#         if char == '年':
#             turtle.write('年', font=("楷体", 24, "normal"))
#             turtle.pencolor(colors[color_index])
#             color_index = (color_index + 1) % 3
#             turtle.fd(60)
#         elif char == '月':
#             turtle.write('月', font=("楷体", 24, "normal"))
#             turtle.pencolor(colors[color_index])
#             color_index = (color_index + 1) % 3
#             turtle.fd(60)
#         elif char == '日':
#             turtle.write('日', font=("楷体", 24, "normal"))
#         else:
#             draw_digit(int(char))

def draw_date(date_str):
    colors = ["red", "green", "blue"]
    color_index = 0
    current_color = colors[color_index]  # 初始化当前颜色

    for char in date_str:
        if char == '年':
            turtle.write('年', font=("楷体", 24, "normal"))
            turtle.pencolor(current_color)  # 使用当前颜色
            color_index = (color_index + 1) % 3  # 递增索引
            current_color = colors[color_index]  # 更新颜色
            turtle.fd(60)
        elif char == '月':
            turtle.write('月', font=("楷体", 24, "normal"))
            turtle.pencolor(current_color)
            color_index = (color_index + 1) % 3
            current_color = colors[color_index]
            turtle.fd(60)
        elif char == '日':
            turtle.write('日', font=("楷体", 24, "normal"))
        else:
            turtle.pencolor(current_color)  # 绘制数字前显式设置颜色
            draw_digit(int(char))


def main():
    turtle.setup(1200, 400)  # 设置画布大小[5](@ref)
    turtle.penup()
    turtle.fd(-550)  # 初始位置左移550像素
    turtle.pensize(5)
    turtle.speed(0)  # 最快绘制速度
    draw_date("2025年03月26日")
    turtle.hideturtle()
    turtle.done()


if __name__ == "__main__":
    main()